from django.contrib import admin
from .models import UploadFileModel, OpenvpnPortModel
import logging
from .business import OpenvpnPortUpdate

# Register your models here.
class OpenvpnPortModelAdmin(admin.ModelAdmin):
    list_display = ('port',)
    def save_model(self, request, obj, form, change):
        if change is False:
            objn = self.model.objects.filter()
            if len(objn) > 0:
                return
        obj.save()
        objup = OpenvpnPortUpdate(obj.port)
        objup.update()
        
    def delete_model(self, request, obj):
        objn = self.model.objects.filter()
        if len(objn) <= 1:
            return
        obj.delete()

admin.site.register(OpenvpnPortModel, OpenvpnPortModelAdmin)

class UploadFileModelAdmin(admin.ModelAdmin):
    list_display = ('desc','file',)
admin.site.register(UploadFileModel, UploadFileModelAdmin)